
package com.ylc.chat.client;

import com.ylc.chat.JUI.LoginFrame;

import javax.swing.*;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;


/**
 * @Author: ylc
 * @Description:客户端入口类
 */
public class ClientMain {

    public static void main(String[] args) {
        connection(); //连接到服务器

        new LoginFrame();  //启动登录窗体
    }

    /** 连接到服务器 */
    public static void connection() {
        String ip = ClientDataBuffer.configProp.getProperty("ip");
        int port = Integer.parseInt(ClientDataBuffer.configProp.getProperty("port"));
        try {
            ClientDataBuffer.clientSocket = new Socket(ip, port);
            ClientDataBuffer.oos = new ObjectOutputStream(ClientDataBuffer.clientSocket.getOutputStream());
            ClientDataBuffer.ois = new ObjectInputStream(ClientDataBuffer.clientSocket.getInputStream());

        } catch (Exception e) {
            JOptionPane.showMessageDialog(new JFrame(),
                    "连接服务器失败,请检查!","服务器未连上", JOptionPane.ERROR_MESSAGE);//否则连接失败
            System.exit(0);
        }
    }
}
